<template>
    <div>
        <Card>
            <!-- search start -->
            <!-- <div class="search">
                <Form :model="search" class="search_box" inline label-position="right">
                    <FormItem label="分部 -> 楼层 -> 区域：">
                        <Cascader filterable class="cascader" :value="cascadeArr" :data="cascadeList" change-on-select @on-change="cascadeSelection" :clearable="false"></Cascader>
                    </FormItem>

                    <FormItem>
                        <Button icon="md-search" type="primary" @click="search_list">搜索</Button>
                    </FormItem>

                </Form>

            </div> -->
            <!-- end search -->

            <Table :loading="loading" stripe :columns="columns1" :data="data1"></Table>
            <Page :total="total" :current="search.page" show-sizer show-total :page-size="search.rows" @on-page-size-change="get_list_by_rows" @on-change="get_list_by_page"> </Page>

        </Card>
    </div>
</template>

<script>
    import axios from '@/libs/api.request'
    import {
        selectDepartment
    } from '@/libs/tools'
    import {
        mapGetters,
        mapMutations
    } from 'vuex'
    export default {
        name: 'scan-total',
        data() {
            return {
                // 加载状态
                loading: false,

                // 级联回显数组
                cascadeArr: [-1],

                // 搜索对象
                search: {
                    // branchid: -1,
                    // floorid: -1,
                    // regionid: -1,
                    page: 1,
                    rows: 10
                },

                // 数据总条数
                total: 0,


                columns1: [{
                        type: 'index',
                        width: 60,
                        align: 'center'
                    },

                    {
                        title: '分部',
                        align: 'center',
                        key: 'branch_zw'
                    },
                    {
                        title: '楼层',
                        align: 'center',
                        key: 'floor_zw'
                    },
                    {
                        title: '工位编号',
                        align: 'center',
                        key: 'number',
                    },
                    {
                        title: '公司名称',
                        align: 'center',
                        key: 'company_name',
                    },
                    {
                        title: '扫描次数',
                        align: 'center',
                        key: 'vr_num'
                    }
                ],
                data1: [],
            }
        },
        methods: {
            ...mapGetters(['getRole', 'getBranchList']),

            // 获取扫描明细列表
            get_scan_total_list() {
                this.loading = true
                let {
                    ...data
                } = this.search
                axios.ajax_post('admin-work_station_scan_total-ajax_get_wsst', data).then(res => {
                    this.loading = false
                    if (res.data.code === 1) {
                        this.data1 = res.data.data.list
                        this.total = res.data.data.total_num

                        if (this.data1.length < 1 && this.total > 0) {
                            this.search.page = Math.ceil(this.total / this.search.rows)
                            this.get_scan_total_list()
                        }
                    } else {
                        this.$Notice.error({
                            title: res.data.msg,
                            duration: 3
                        })
                    }
                })
            },

            // 级联选择
            cascadeSelection(value) {

                value = value.map(Number)

                this.cascadeArr = value
                if (value.length == 1) {
                    this.search.branchid = value[0]
                    this.search.floorid = -1
                    this.search.regionid = -1
                    return false
                }
                if (value.length == 2) {
                    this.search.branchid = value[0]
                    this.search.floorid = value[1]
                    this.search.regionid = -1
                    return false
                }
                this.search.branchid = value[0]
                this.search.floorid = value[1]
                this.search.regionid = value[2]
            },

            // 格式化时间
            changeTime(value) {
                this.search.start_time = value[0]
                this.search.end_time = value[1]
            },

            // 搜索
            search_list() {
                this.search.page = 1
                this.search.rows = 10
                this.get_scan_total_list()
            },

            get_list_by_rows(rows) {
                this.search.rows = rows
                this.get_scan_total_list()
            },

            get_list_by_page(page) {
                this.search.page = page
                this.get_scan_total_list()
            },
        },
        computed: {
            cascadeList() {
                let list = JSON.parse(JSON.stringify(this.getBranchList()))
                list.unshift({
                    value: -1,
                    label: '全部'
                })
                return list
            },
            role() {
                return this.getRole()
            }
        },
        created() {
            this.get_scan_total_list()
        },
    }
</script>

<style lang="less" scoped>
    .search {
        .search_box {
            display: flex;
            flex-wrap: wrap;

            .option {
                width: auto;
            }

            .ivu-form-item {
                margin-right: 12px;
                display: flex;
                justify-content: flex-start;
                margin-bottom: 20px;
            }
        }
    }
</style>